package com.front.teacher.teacherapp.model;

import android.os.Handler;
import android.util.Log;

import com.front.teacher.teacherapp.api.ApiService;
import com.front.teacher.teacherapp.api.RetrofitHelper;
import com.front.teacher.teacherapp.api.UrlConfig;
import com.front.teacher.teacherapp.bean.ResultEnity;
import com.front.teacher.teacherapp.model.impl.ILoginBiz;
import com.front.teacher.teacherapp.model.impl.OnLoginListener;
import com.front.teacher.teacherapp.utils.AESUtils;
import com.front.teacher.teacherapp.utils.SharedPreferencesHelper;

import java.io.IOException;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2016/8/9.
 */
public class LoginModel implements ILoginBiz {
    private Handler handler = new Handler();
    @Override
    public void getData(String userName, String password, OnLoginListener loginListener) {
        RetrofitHelper helper = RetrofitHelper.getInstance();
        ApiService service = helper.getService();
        String tokenCode = AESUtils.Encrypt(password);
        Call<ResponseBody> call = service.getLogin(UrlConfig.DefaultVAULE.DEFAULT_VAULE_TYPE, tokenCode, userName);
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                try {
                    String content = response.body().string();
                    Log.i("---tag---",content);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
            }
        });
//        判断登陆是否成功
        if ("20160523001".equals(userName)&&"001".equals(password)){
            loginListener.loginSuccess();
        }else {
            loginListener.loginFail();
        }
    }
}
